package domain

// User 实体
type User struct {
	ID      string
	Name    string
	Email   *Email
	Address *Address
}

// NewUser 创建一个新的用户
func NewUser(id, name, email, street, city, state, country string) (*User, error) {
	emailObj, err := NewEmail(email)
	if err != nil {
		return nil, err
	}

	addressObj, err := NewAddress(street, city, state, country)
	if err != nil {
		return nil, err
	}

	return &User{
		ID:      id,
		Name:    name,
		Email:   emailObj,
		Address: addressObj,
	}, nil
}

// ChangeEmail 修改用户的邮箱
func (u *User) ChangeEmail(newEmail string) error {
	emailObj, err := NewEmail(newEmail)
	if err != nil {
		return err
	}
	u.Email = emailObj
	return nil
}

// ChangeAddress 修改用户的地址
func (u *User) ChangeAddress(street, city, state, country string) error {
	addressObj, err := NewAddress(street, city, state, country)
	if err != nil {
		return err
	}
	u.Address = addressObj
	return nil
}
